
import RescacheMgr from "../framework/inc/rescachemgr";
import EffStar from "../stage3d/component/effstar";
import EffGround from "./component/effground";
import WeatherSnow from "./component/weathersnow";
import * as THREE from "../../three.module";

var OrbitControls = require('three-orbitcontrols')

export default class SceneUsr extends THREE.Scene {
    constructor(camera, render) {
        super();
        this._camera = camera;
        this._render = render;

        this._debugCtl();
        this._debugUI();

        let inc = RescacheMgr.getInstance();
        inc.preload(() => {
            console.log("load end!");

            this.test_shaderground();
            this.test_shadersnow();
        });
    }

    test_shaderground() {
        let inc = RescacheMgr.getInstance();
        let effground = new EffGround(
            100.0,
            100.0,
            20.1,
            {
                texture1: inc.getTexture("ground_texture1"),
                texture2: inc.getTexture("ground_texture2"),
                texture3: inc.getTexture("ground_texture3"),
                heightmap: inc.getTexture("ground_heightmap"),
                texturemap: inc.getTexture("ground_texturemap"),
            }
        );
        this.add(effground);
        effground.position.set(0, 0, -1);
        this._effground = effground;

    }

    test_shadersnow() {
        let weather = new WeatherSnow(
            100, 100
        );
        this.add(weather);
        weather.position.set(0, 0, -1);
    }

    _debugUI() {
        const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
        const material = new THREE.MeshNormalMaterial();
        const mesh = new THREE.Mesh(geometry, material);
        this._mesh = mesh;
        this.add(mesh);

        const geometry2 = new THREE.BoxGeometry(0.2, 0.2, 0.2);
        const material2 = new THREE.MeshNormalMaterial();
        const mesh2 = new THREE.Mesh(geometry2, material2);
        mesh2.scale.set(10);
        this._mesh2 = mesh2;
        this.add(mesh2);

        mesh2.position.z = -2;
    }

    _debugCtl() {
        let control = new OrbitControls(this._camera, this._render.domElement);
        control.enableDamping = true;
        control.enableZoom = true;
    }

    update() {
        if (this._mesh) {
            this._mesh.rotation.x += 0.01;
            this._mesh.rotation.y += 0.02;
        }
        if (this._effstar) {
            this._effstar.update();
        }
    }
}